package com.zt.java.concurrency.synchronize;

import org.openjdk.jol.info.ClassLayout;

/**
 * 轻量级锁
 * 观察markword的值
 */
public class JOL4 {

    public static void main(String[] args) throws InterruptedException {
        Thread.sleep(5000);
        Object o = new Object();
        synchronized (o) {
            System.out.println(ClassLayout.parseInstance(o).toPrintable());
        }

        for (int i = 0; i < 1; i++) {
            Thread t = new Thread(() -> {
                print(o);
            });
            t.start();
        }
    }

    public static void print(Object o) {
        synchronized (o){
            System.out.println(ClassLayout.parseInstance(o).toPrintable());
        }
    }
}
